<%-- 
    Document   : Pay
    Created on : 28/11/2010, 06:26:50 PM
    Author     : Rainiero
--%>

<%@page import="Gui.*"%>
<%@page import="ServiceInterface.IFacade"%>
<%@page import="DataModel.*"%>
<%@page import="Proxy.ProxySAFP"%>
<%

    String header = GuiHelper.GetInstance().GetHeader();
    String footer = GuiHelper.GetInstance().GetFooter();

    IFacade facade = new ProxySAFP().getServiceInterface();

    int paymentId = RequestHelper.GetPaymentId(request);
    String realDate = "", estimatedDate = "";
    String realAmount = "", estimatedAmount = "";
    String products = "";
    String disable = "disabled";

    if(paymentId != -1)
    {
        Payment payment = facade.GetPayment(paymentId);
        if(payment != null)
        {
            GuiHelper guiHelper = GuiHelper.GetInstance();
            estimatedAmount = guiHelper.GetCurrencyText(payment.getEstimatedAmount());
            estimatedDate = guiHelper.GetFormattedDate(payment.getEstimatedDate());
            if(payment.getStatus() == Enums.PaymentStatus.Payed)
            {
                realDate = guiHelper.GetFormattedDate(payment.getRealDate());
                realAmount = guiHelper.GetCurrencyText(payment.getRealAmount());
            }
            else
            {
                realDate = "<input type=\"text\" name=\"txtDate\">";
                realDate += "<script language=\"JavaScript\" type=\"text/javascript\">";
                realDate += "new tcal ({'formname': 'form1', 'controlname': 'txtDate' });";
                realDate += "</script>";
                realAmount = "<input type=\"text\" id=\"txtAmount\" name=\"txtAmount\">";
                disable = "";
            }

            String style = "";
            for(int productIndex = 0; productIndex < payment.getProducts().length; productIndex++)
            {
                Product product = payment.getProducts()[productIndex];
                if(productIndex % 2 == 0)
                    style = "alternateRow";
                products += "<tr>";
                products += String.format("<td class=\"%2$s\">%1$s</td>", product.getName(), style);
                products += String.format("<td class=\"%2$s\">%1$s</td>", product.getDescription(), style);
                products += "</tr>";
            }
        }
    }

%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Registro de desembolso</title>
        <script language="JavaScript" src="../../calendar/calendar_us.js" type="text/javascript"></script>
        <link rel="stylesheet" href="../../calendar/calendar.css">
        <link rel="stylesheet" type="text/css" href="../Styles/safp.css" />
    </head>
    <body>
        <%= header %>
        <h1>Registro de desembolso</h1>
        <form action="../../srvPay" method="post" name="form1" >
            <input type="hidden" id="hdPayment" name="hdPayment" value="<%= paymentId %>">
            <h2>Información Financiera</h2>
            <table>
                <tr>
                    <td class="label">Fecha estimada:</td>
                    <td class="data"><%= estimatedDate %></td>
                </tr>
                <tr>
                    <td class="label">Monto estimado:</td>
                    <td class="data"><%= estimatedAmount %></td>
                </tr>
                <tr>
                    <td class="label">Fecha real:</td>
                    <td class="data"><%= realDate %></td>
                    <!-- //TODO: Validar datos -->
                </tr>
                <tr>
                    <td class="label">Monto real:</td>
                    <td class="data"><%= realAmount %></td>
                </tr>
                <tr>
                    <td align="right" colspan="2">
                        <input type="submit" value="Registrar desembolso" <%= disable %>>
                    </td>
                </tr>
            </table>
            <h2>Productos asociados</h2>
            <table border="1">
                <tr>
                    <td>Nombre</td>
                    <td>Descripción</td>
                </tr>
                <%= products %>
            </table>
        </form>
        <%= footer %>
    </body>
</html>
